<template>
  <!-- 关注列表学员 -->
  <div class="content">

    <el-table :data="focusList" style="width: 100%">
      <el-table-column prop="id" label="id" width="180">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="180">
      </el-table-column>
      <el-table-column prop="class_times" sortable label="参加表达课次数">
      </el-table-column>
      <el-table-column prop="age" label="年龄">
      </el-table-column>
      <el-table-column prop="school" label="毕业院校">
      </el-table-column>
      <el-table-column prop="edu_level_str" label="学历">
      </el-table-column>
      <el-table-column prop="now_salary_str" sortable label="目前薪资水平">
      </el-table-column>
      <el-table-column prop="hope_salary_str" sortable label="期望薪资水平">
      </el-table-column>

      <el-table-column label="操作" width="180">
        <template scope="scope">
          <el-button @click="studentDetail(scope.$index)" type="text" size="small">详情</el-button>
          <el-button @click="cancelFocus(scope.$index)" type="text" size="small">取消关注</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
import { fetchHrFocusList,changeHrFocusStatus } from 'api/remoteSearch';
import { mapGetters } from 'vuex';
export default {
  data() {
    return {
      focusList: []
    }
  },
  computed: {
    ...mapGetters([
      'user_id',
      'roles'
    ])
  },
  mounted() {
    if (this.roles.indexOf('hr') == -1) {
      this.$router.push({ path: '/' })
    }
    this.getFocusList();
  },
  methods: {
    getFocusList() {
      let vm = this;
      fetchHrFocusList(vm.user_id)
        .then(res => {
          if (res.data.status == 'success') {
            vm.focusList = res.data.focus_list;
          }else{
            vm.$message({type:'error',message:'获取猎头关注列表失败'});
          }
        }).catch(err => {

        })
    },
    studentDetail(index) {
      //查看学生详情
      console.log(index)
      let id=this.focusList[index].id;
      this.$router.push({path:"/student/"+id})
    },
    cancelFocus(index){
      let vm=this;
       let studentId=this.focusList[index].id;
      changeHrFocusStatus(this.user_id,studentId,false)
      .then(res=>{
        if(res.data.status=='success'){
          vm.$message({type:'info',message:res.data.msg})
          vm.focusList.splice(index,1);
        }
        else{
           vm.$message({type:'error',message:res.data.msg})
        }
      })
      .catch(err=>{

      })
    }
  }
}
</script>

<style>

</style>
